package org.glorylight.hacks.social.service;

import java.util.UUID;

import org.glorylight.hacks.social.data.InvitationData;
import org.glorylight.hacks.social.model.InvitationLog;
import org.glorylight.hacks.social.util.ModelHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class InvitationService extends BaseService {
	
	private static final Logger log = LoggerFactory.getLogger(InvitationService.class);

	@Transactional(readOnly = false)
	public void addInvitation(InvitationData data) {
		if (log.isDebugEnabled())
			log.debug("adding new invitation for: {}", data.getRecipient());
		add(ModelHelper.convertInvitationData(data));
	}
	
	public boolean isInvitationExist(UUID id) {
		return (find(id)!= null);
	}
	
	public InvitationData find(UUID id) {
		if (log.isDebugEnabled())
			log.debug("retrieve Message: {}", id);
		InvitationLog inv = em.find(InvitationLog.class, id);
		if (inv != null)
			return ModelHelper.convertInvitationLog(inv);
		else
			return null;
	}
}
